# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: speps <speps at aur dot archlinux dot org>
# Contributor: Philipp Überbacher <murks at lavabit dot com>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - disable SSE

pkgbase=zita-resampler
pkgname=(
  zita-resampler
  zita-resampler-docs
)
pkgver=1.11.2
pkgrel=2
pkgdesc="A C++ library for resampling audio signals"
arch=(x86_64)
url="https://kokkinizita.linuxaudio.org/linuxaudio"
license=(GPL-3.0-or-later)
makedepends=(
  gcc-libs
  glibc
  libsndfile
)
source=($url/downloads/$pkgname-$pkgver.tar.xz)
sha512sums=('1598c9ead4bf858d3a11677c9512932077e1d0b83588682eba402820936fa1cfc5fe1112abbecd945469b4ae2f7a6f59938a5fbb0fdd79de3b0a3a73703b03dd')
b2sums=('627b309b38b238902b1cad2cb0963d0182f8f4cc4bc72efcd2b9ecc9810f019968c141e31ffb94110e8c4ca781e1c57b7d3393a3d4699b3f90873958b34ce47c')

prepare() {
  cd $pkgname-$pkgver
  # remove march=native
  sed -e '/native/d' -i {source,apps}/Makefile
  # disable SSE
  sed -e '/ENABLE_SSE2/d' -i source/Makefile
}

build() {
  cd $pkgname-$pkgver
  # libs
  make -C source
  # create lib link for building apps
  ln -sv lib$pkgname.so.$pkgver source/lib$pkgname.so
  # apps
  make LDFLAGS+=" -L../source" CXXFLAGS+=" -I../source" -C apps
  # cleanup link
  rm -rv source/lib$pkgname.so
}

package_zita-resampler() {
  depends=(gcc-libs glibc)
  optdepends=(
    'libsndfile: for zresample and zretune'
    'zita-resampler-docs: for documentation'
  )
  provides=(libzita-resampler.so)

  for location in $pkgbase-$pkgver/{source,apps}; do
    make DESTDIR="$pkgdir/" PREFIX=/usr SUFFIX="" install -C $location
  done
}

package_zita-resampler-docs() {
  pkgdesc+=" - documentation"

  install -vDm 644 $pkgbase-$pkgver/{AUTHORS,README,docs/*}  -t "$pkgdir/usr/share/doc/$pkgbase/"
}
